#include "msgq.h"
#include "bank.h"
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int msgid = 0;
MSG_CTOS ctos = {};
MSG_STOC stoc = {};

void query(void)
{
	char path[80] = {};
	char path0[40] = ACCOUNT_PATH;
	sprintf(path,"%s%s.dat",path0,ctos.acc.id);
	
	int fd = open(path,O_RDWR);
	int ret = read(fd,&stoc.acc,sizeof(Account));
	if(ret == 0)
	{
		strcpy(stoc.info,"read");
		puts(stoc.info);	//服务器出错输出错误位置
	}
	else strcpy(stoc.info,"success");
	close(fd);
}

int main(int argc,const char* argv[])
{
	printf("argv %s\n",argv[0]);
	msgid = get_msg(ACCOUNT_PATH,SUBP_CNT);
	
	for(;;)
	{
		recv_msg(msgid,&ctos,sizeof(MSG_CTOS),MSGTY_QUERY);
		query();
		stoc.type = ctos.return_type;
		send_msg(msgid,&stoc,sizeof(MSG_STOC));
	}	
}
